package com.itstyle.quartz.interceptor;

import com.alibaba.fastjson.JSONObject;
import com.itstyle.quartz.entity.QuartzEntityBatchDt;
import com.itstyle.quartz.kettleUtil.kettleUtil;
import org.pentaho.di.core.Result;
import org.quartz.JobKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class CompareTableBatch {
    private static final Logger logger = LoggerFactory.getLogger(CompareTableBatch.class);

    public Result runBatchJob(List<QuartzEntityBatchDt> BatchDt, JobKey jobkeys) throws Exception{
        String path=null;
        Result result = null;
          for(int i=0;i<BatchDt.size();i++){
              logger.info("线程内部开始循环调用job进行批量表同步操作 jobkeys="+jobkeys);
              QuartzEntityBatchDt quartz = BatchDt.get(i);
              JSONObject jsonObject = new JSONObject();
              jsonObject.put(quartz.getSOURCENAME(),quartz.getTABLENAME());
              jsonObject.put(quartz.getTARGETNAME(),quartz.getTARGETTABLENAME());
              path = quartz.getKETTLEPATCH();
              logger.info("批量任务任务开始调用执行JOB：jobkeys="+jobkeys.toString());
              result = kettleUtil.runJob(jsonObject,path);
              logger.info("批量任务任务开始调用执行JOB结束：jobkeys="+jobkeys.toString()+"; result"+result.toString());
              logger.info("线程内部循环调用job进行批量表同步操作结束：jobkeys="+jobkeys.toString());
          }

        return result;
    }
}
